package cn.com.iresearch.android.componentizationsupporter

import android.content.Context
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast


/**
Created By: Seal.Wu
Date: 2018/4/3
Time: 11:01
 */
class TestComponentTwo : IComponent {
    override fun getComponentName(): String {
        return "TestComponentTwo"
    }


    override fun execute(commandLine: String, vararg commandLineArgs: Any): Any {
        when (commandLine) {
            "toast" -> {
                val arg1 = commandLineArgs[0]
                if (arg1 is Context) {
                    Handler(Looper.getMainLooper()).post {
                        Toast.makeText(arg1, "This is ${getComponentName()}", Toast.LENGTH_LONG).show()
                    }

                    return Any()
                } else {
                    throw IllegalArgumentException("No compatible args")
                }

            }

            "log" -> {
                Log.i("ComponentizationSupporter", "This is ${getComponentName()}")
            }

            "getComponentKey" -> return "TestComponentTwo"
        }

        return Any()
    }

    override fun executeAsync(commandLine: String, vararg commandLineArgs: Any, callback: (response: Any) -> Unit) {
    }

}